package com.kele.message.response.write;

import io.netty.buffer.ByteBuf;

/**
 * 功能码为0x10的应答帧
 * 写多个寄存器的应答帧
 */
public class WriteMultipleRegistersResponseFrame extends WriteResponseFrame{

    /**
     * 寄存器数量
     */
    private int length;

    /**
     * 字节数量
     */
    private int byteLength;

    @Override
    public void decode(ByteBuf in, int addressCode, int functionCode) {
        this.setFunctionCode(functionCode);
        this.setAddressCode(addressCode);
        this.setAddress(in.readShort());
        this.setLength(in.readShort());
        this.setByteLength(in.readByte());
        this.setContent(in.readRetainedSlice(this.byteLength));
        this.setCheckCode(in.readRetainedSlice(2));
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getByteLength() {
        return byteLength;
    }

    public void setByteLength(int byteLength) {
        this.byteLength = byteLength;
    }

    @Override
    public String toString() {
        return "WriteMultipleRegistersResponseFrame{" +
                "length=" + length +
                ", byteLength=" + byteLength +
                "} " + super.toString();
    }
}
